// var mapWx = require('../../../../common/js/map/qqmap-wx-jssdk.min.js')

// var qqmapsdk = new mapWx({
// 	key: "UXDBZ-42ZKQ-XCX52-BRYQS-64LC2-IHF34"
// })
export default {
	data() {
		return {
			latitude: null, // 纬度
			longitude: null, // 经度
			activeId: null,
			catList: [],
			catListMain:[],
		};
	},
	onLoad(data) {
		uni.hideTabBar();
		this.name = 'DIY_VIEW_INDEX';
		// this.getLoaction()
		
		if(data && data.number) uni.setStorageSync('invite_id', data.number)
		
		// 小程序扫码进入
		if (data.scene) {
			var sceneParams = decodeURIComponent(data.scene);
			sceneParams = sceneParams.split('&');
			if (sceneParams.length) {
				sceneParams.forEach(item => {
					if (item.indexOf('m') != -1) uni.setStorageSync('invite_id', item.split('-')[1]);
				});
			}
		}
		this.getCatData()
		this.getCatData2()
		this.getInfo()
	},
	onShow() {
		
	},
	methods: {
		getCatData() {
			
			this.$api.sendRequest({
				url: '/api/goodscategory/treeNav?level=2',
				success: res => {
					this.catList = res.data
					uni.setStorageSync('cat_list',this.catList)
				}
			})
		},
		getCatData2() {
			
			this.$api.sendRequest({
				url: '/api/goodscategory/treeMain?level=1',
				success: res => {
					this.catListMain = res.data
					
				}
			})
		},
		getLocation() {
			
		},
		getInfo() {
			this.$api.sendRequest({
				url: '/api/member/info',
				success: res => {
					  const { location } = res.data; 
					  if (location) {
						const objs = { val: location };
						this.catList.forEach(item => {
						  if (item.category_id == location) {
							objs.name = item.category_name || ''; 
						  }
						});
						uni.setStorageSync('act_location', objs);
					  }
					},				
				complete: () => {
					this.getLocation()
				}
			});
		},
		active(v,i) {
			let obj = {
				name: v.category_name,
				val: v.category_id
			}
			this.activeId = obj.val
			if(obj.val) uni.setStorageSync('act_location',obj)
			this.$refs.actLocationPop.close()
		}
		// selectMap() {
		// 	let that = this //在uniapp中药定义一下this才能使用
		// },
		// loAcquire(longitude, latitude) {
		// 	let that = this;
		// 	uni.showLoading({
		// 		title: '加载中',
		// 		mask: true
		// 	});
		// 	let str = `key=UXDBZ-42ZKQ-XCX52-BRYQS-64LC2-IHF34&location=${latitude},${longitude}` //记得在这里要输入密钥哦！
		// 	this.$api.sendRequest({
		// 		url: 'https://apis.map.qq.com/ws/geocoder/v1/?' + str,
		// 		success: res => {
		// 			uni.hideLoading();
		// 			if (res.status == 0) {
		// 				console.log('当前位置是:' + res.result.address_component.street_number)
		// 			} else {
		// 				this.$util.showToast({
		// 					title: res.message
		// 				});
		// 			}
		// 		},
		// 		fail: (err) => {
		// 			uni.hideLoading();
		// 		}
		// 	},2)
		// },
		// getLoaction() {
		// 	let that = this
		// 	if(this.location) {
		// 		this.latitude = this.location.latitude;
		// 		this.longitude = this.location.longitude;
		// 	} else {
		// 		// #ifdef MP-WEIXIN
		// 		uni.getSetting({
		// 		   success(res) {
		// 			   let authObj = res.authSetting
		// 				if(typeof authObj['scope.userLocation'] == 'undefined') {
		// 				   that.$refs.locationPop.open()
		// 				} else if (authObj['scope.userLocation'] == false) {
		// 				   // 如果没授权,则执行后续操作
		// 				   that.$refs.locationPopTop.open()
		// 				} else {
		// 					that.confim()
		// 				}
		// 		   }
		// 		})
		// 		// #endif
		// 	}
		// },
		// cancel() {
		// 	this.$refs.locationPop.close()
		// },
		// cancels() {
		// 	this.$refs.locationPopTop.close()
		// },
		// confim() {
		// 	let that = this
		// 	this.$util.getLocation({
		// 		success(res) {
		// 			that.cancel()
		// 		},
		// 		fail(err) {
		// 			that.$refs.locationPopTop.open()
		// 		},
		// 		complete() {
		// 			that.cancel()
		// 		}
		// 	});
		// },
		// confims() {
		// 	let that = this
		// 	uni.openSetting({
		// 	  success(res) {
		// 		  let authObj = res.authSetting
		// 		  if (authObj['scope.userLocation'] == false) {
		// 		     // 如果没授权,则执行后续操作
		// 		     that.$refs.locationPopTop.open()
		// 		  }
		// 	  },
		// 	  complete() {
		// 	  	that.cancels()
		// 	  }
		// 	});
		// }
	},
}
